<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="../js/MockajaxUtil.js"></script>
    <script src="../js/utils.js"></script>
    <script src="../js/table/htmlUtils.js"></script>
    <script src="../js/table/tableBuild.js"></script>
    <script src="../js/table/tableDefinition-bom.js"></script>
    <link rel="stylesheet" href="../css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../css/jeesite.min.css"/>
    <title></title>
</head>
<body>
<div id="content"></div>
需要操作的行号 <input type="text" id="operateIndex"/>
<input type="button" onclick="reRender();" value="重置"/>
</body>
<script>
    let builder = undefined;
    // doGet('www.baidu.com/materials', (data) => {
        doGet('www.baidu.com/bom/data?materials', (data) => {
        builder = new TableBuilder('content', tableDefinition, columnsDefinition, data);
        builder.build();
    });


    function reRender() {
        let index = $("#operateIndex").val();
        // builder.reRender(index, {});
        builder.reRender(index, {
            "id": 1877157,
            "assortid": "20000003",
            "idnrk": "000000000060000014",
            "menge": 0,
            "price": 0,
            "supplier": "",
            "maktx": "能源电",
            "meins": "D46",
            "category": "能源电",
            "potx": "备注信息",
            "lkenz": "0",
            "bomVersion": "1",
            "wastageRate": "",
            "prdha": "60002001",
            "nhlx": "02",
            "ff": false
        });
    }

    function deleteTr(obj) {
        builder.removeRowByPrefixButton(obj);
    }

    function appendTr(obj) {
        builder.addOneRow();
    }

    function getSupp(obj) {
        debugFunction("getSupp", obj);
    }

    function calPrice(obj) {
        debugFunction("calPrice", obj);
    }

    function checkMaterial(obj) {
        debugFunction('checkMaterial', obj)
    }

    function renderCode(item, tableDefinition) {
        let idnrk = item.idnrk;
        if (undefined == idnrk) {
            return '<td class="bgcolorth" style="width: 10%" ondblclick="checkMaterial(this)">   <input name="idnrk1" placeholder="双击选择组件" style="padding: 0;margin: 0;text-align: center;border:none;width: 100%;" readonly="">   <input name="idnrk" placeholder="双击选择组件" style="padding: 0;margin: 0;text-align: center;border:none;width: 100%;" type="hidden"></td>';
        } else {
            return '<td class="bgcolorth" style="width: 10%" ondblclick="checkMaterial(this)">   <input name="idnrk1" placeholder="双击选择组件" style="padding: 0;margin: 0;text-align: center;border:none;width: 100%;" readonly="" value="' + item.idnrk.replace(/^0*([1-9]\d*)$/, '$1') + '">   <input name="idnrk" placeholder="双击选择组件" style="padding: 0;margin: 0;text-align: center;border:none;width: 100%;" type="hidden" value="' + item.idnrk + '"></td>';
        }
    }

    function renderStatus(item, tableDefinition) {
        let value = item['dataStatus'];
        let td = '<td class="bgcolorth" style="width: 5%">     <input name="lkenz1" style="padding: 0;margin: 0;border:none;text-align: center;width: 100%;" readonly="" value="★">     <input name="lkenz" style="padding: 0;margin: 0;border:none;text-align: center;width: 100%;" type="hidden"';
        if (undefined !== value) {
            td += ' value="' + value + '"';
        }
        td += '/></td>';
        return td;
    }

    function debugFunction(functionName, params) {
        console.log("function " + functionName);
        if (params == Window) {
            console.log("params Window对象");
            return;
        }
        if (params instanceof Object) {
            console.log("params " + JSON.stringify(params));
        } else {
            console.log("params " + params);
        }
    }
</script>
</html>
